<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>大模型分析 - 股票新闻分析系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    <style>
        .analysis-card {
            margin-bottom: 1.5rem;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            transition: transform 0.3s;
        }

        .analysis-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
        }

        .market-commentary {
            background-color: #f8f9fa;
            border-left: 4px solid #0d6efd;
            padding: 1rem;
            margin-bottom: 1.5rem;
        }

        .theme-card {
            border-left: 4px solid #198754;
            margin-bottom: 1rem;
        }

        .stock-rating {
            font-weight: bold;
        }

        .rating-buy {
            color: #198754;
        }

        .rating-hold {
            color: #fd7e14;
        }

        .rating-sell {
            color: #dc3545;
        }

        .indicator-item {
            background-color: #e9ecef;
            padding: 0.5rem;
            margin-bottom: 0.5rem;
            border-radius: 0.25rem;
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">股票新闻分析系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('dashboard') }}">数据仪表盘</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('reports') }}">策略报告</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="{{ url_for('llm_analysis') }}">大模型分析</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <div class="container mt-4">
        <h1 class="mb-4">大模型分析</h1>

        <!-- 数据分析状态 -->
        {% if llm_data %}
        <div class="alert alert-success" role="alert">
            <h4 class="alert-heading">数据分析完成！</h4>
            <p>大语言模型已成功分析当前市场数据，为您提供深度洞察和投资建议。</p>
            <hr>
            <p class="mb-0">最后更新时间: {{ llm_data.get('timestamp', '未知') }}</p>
        </div>

        <!-- 市场评论 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header bg-primary text-white">
                        <h2 class="h5 mb-0">市场深度评论</h2>
                    </div>
                    <div class="card-body">
                        <div class="market-commentary">
                            <p>{{ llm_data.get('market_commentary', {}).get('market_commentary', '暂无市场评论') }}</p>
                        </div>

                        <h3 class="h5 mt-4">宏观经济因素</h3>
                        <p>{{ llm_data.get('market_commentary', {}).get('economic_factors', '暂无宏观经济分析') }}</p>

                        <h3 class="h5 mt-4">行业轮动分析</h3>
                        <p>{{ llm_data.get('market_commentary', {}).get('sector_rotation', '暂无行业轮动分析') }}</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- 投资主题 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header bg-success text-white">
                        <h2 class="h5 mb-0">热门投资主题</h2>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            {% for theme in llm_data.get('market_commentary', {}).get('investment_themes', []) %}
                            <div class="col-md-6 mb-3">
                                <div class="card theme-card">
                                    <div class="card-body">
                                        <h3 class="h6">{{ theme.get('theme', '未知主题') }}</h3>
                                        <p class="card-text">{{ theme.get('rationale', '暂无说明') }}</p>
                                    </div>
                                </div>
                            </div>
                            {% endfor %}
                        </div>

                        {% if not llm_data.get('market_commentary', {}).get('investment_themes') %}
                        <div class="alert alert-info">暂无投资主题数据</div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 股票深度分析 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header bg-info text-white">
                        <h2 class="h5 mb-0">股票深度分析</h2>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            {% for stock_code, analysis in llm_data.get('stock_analysis', {}).get('stock_analysis',
                            {}).items() %}
                            <div class="col-md-6 mb-3">
                                <div class="card analysis-card">
                                    <div class="card-header">
                                        <div class="d-flex justify-content-between align-items-center">
                                            <h3 class="h6 mb-0">{{ analysis.get('stock_name', stock_code) }}</h3>
                                            {% if analysis.get('rating') == '强买入' or analysis.get('rating') == '买入' %}
                                            <span class="badge bg-success">{{ analysis.get('rating') }}</span>
                                            {% elif analysis.get('rating') == '强卖出' or analysis.get('rating') == '卖出' %}
                                            <span class="badge bg-danger">{{ analysis.get('rating') }}</span>
                                            {% else %}
                                            <span class="badge bg-warning text-dark">{{ analysis.get('rating', '持有')
                                                }}</span>
                                            {% endif %}
                                        </div>
                                    </div>
                                    <div class="card-body">
                                        <p class="card-text analysis-text">{{ analysis.get('analysis', '暂无分析') }}</p>
                                    </div>
                                </div>
                            </div>
                            {% endfor %}
                        </div>

                        {% if not llm_data.get('stock_analysis', {}).get('stock_analysis') %}
                        <div class="alert alert-info">暂无股票深度分析数据</div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 投资组合建议 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header bg-warning text-dark">
                        <h2 class="h5 mb-0">投资组合建议</h2>
                    </div>
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>股票代码</th>
                                        <th>配置比例</th>
                                        <th>持有期限</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for rec in llm_data.get('stock_analysis', {}).get('portfolio_recommendations',
                                    []) %}
                                    <tr>
                                        <td>{{ rec.get('stock_code', '') }}</td>
                                        <td>{{ rec.get('proportion', '') }}</td>
                                        <td>{{ rec.get('holding_period', '') }}</td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>

                        {% if not llm_data.get('stock_analysis', {}).get('portfolio_recommendations') %}
                        <div class="alert alert-info">暂无投资组合建议</div>
                        {% endif %}

                        <!-- 投资策略 -->
                        <h3 class="h5 mt-4">不同风险偏好的投资策略</h3>
                        <div class="row">
                            {% for strategy_type, strategy_desc in llm_data.get('stock_analysis', {}).get('strategies',
                            {}).items() %}
                            <div class="col-md-4 mb-3">
                                <div class="card">
                                    <div class="card-header">
                                        <h4 class="h6 mb-0">{{ strategy_type }}</h4>
                                    </div>
                                    <div class="card-body">
                                        <p>{{ strategy_desc }}</p>
                                    </div>
                                </div>
                            </div>
                            {% endfor %}
                        </div>

                        {% if not llm_data.get('stock_analysis', {}).get('strategies') %}
                        <div class="alert alert-info">暂无投资策略数据</div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 关键指标监控 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header bg-secondary text-white">
                        <h2 class="h5 mb-0">关键指标监控</h2>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            {% for indicator in llm_data.get('market_commentary', {}).get('key_indicators', []) %}
                            <div class="col-md-6 mb-2">
                                <div class="indicator-item">
                                    {{ indicator }}
                                </div>
                            </div>
                            {% endfor %}
                        </div>

                        {% if not llm_data.get('market_commentary', {}).get('key_indicators') %}
                        <div class="alert alert-info">暂无关键指标数据</div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        {% else %}
        <!-- 无数据状态 -->
        <div class="alert alert-warning" role="alert">
            <h4 class="alert-heading">暂无大模型分析数据！</h4>
            <p>系统尚未生成大模型分析数据，可能的原因：</p>
            <ul>
                <li>系统正在进行分析，请稍后刷新页面</li>
                <li>未启用大模型分析功能</li>
                <li>分析过程中出现错误</li>
            </ul>
            <hr>
            <p class="mb-0">请确保系统配置正确，并且已经收集了足够的新闻和市场数据。</p>
        </div>
        {% endif %}

        <!-- 关于大模型分析 -->
        <div class="card mt-4 mb-4">
            <div class="card-header bg-dark text-white">
                <h2 class="h5 mb-0">关于大模型分析</h2>
            </div>
            <div class="card-body">
                <p>本系统使用先进的大语言模型（LLM）对金融新闻和市场数据进行深度分析，为投资决策提供更全面的洞察。</p>
                <h3 class="h6">大模型分析优势：</h3>
                <ul>
                    <li>自动提取新闻中的深层洞察和市场情绪</li>
                    <li>基于大量历史数据和知识，提供更全面的市场评估</li>
                    <li>识别潜在的投资主题和行业趋势</li>
                    <li>结合定量分析和定性分析，优化投资决策</li>
                    <li>自动生成结构化的市场评论和投资建议</li>
                </ul>
                <div class="alert alert-info">
                    <i class="bi bi-info-circle"></i> 本分析仅供参考，不构成投资建议。投资有风险，决策需谨慎。
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-4 mt-4">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h5>股票新闻分析系统</h5>
                    <p>基于新闻情感分析和大模型技术的投资决策支持系统</p>
                </div>
                <div class="col-md-6 text-md-end">
                    <p>&copy; 2025 股票新闻分析系统 版权所有</p>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>